home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.ner.bbnplanet.net!daprez!panther!otisg
- From: otisg@panther.middlebury.edu (Otis Gospodnetic)
- Subject: simple code, argc, argv, strcmp()
- Message-ID: <11f7cc$17261a.3b3@daprez>
- Date: Thu, 01 Feb 1996 04:38:26 GMT
- Keywords: strcmp encode decode argc argv
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi, a C question...
- this one has been bothering ALL afternoon !
-
- This snippet of code is supposed to call appropriate function based on what
- command line arguments are supplied.
-
- usage: <program> -e [SourceFile] RemoteFile
- or
- <program> -d [InFile]
-
- if the person doesn't use this right the program is supposed to call Usage()
- which is not here, but it's in my code, and if the person calls the program
- the correct way one of the two actions should be taken (encode or decode).
-
- Problem - I am doing something wrong and I almost always end up calling
- Usage() even if I use the program correctly.
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int main (int argc, char **argv) {
-
- void Usage (void);
- void Encode (int, char **);
- void Decode (int, char **);
-
- if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
- Usage();
- }
- if (strcmp(argv[1],"-d") && argc < 3) {
- printf ("D %i\n", argc);
- Usage();
- }
- if (strcmp(argv[1],"-e") && argc < 4) {
- printf ("E %i\n", argc);
- Usage();
- }
- if (strcmp(argv[1],"-d") && argc == 3) {
- Decode(argc, argv);
- }
- if (strcmp(argv[1],"-e") && argc == 4) {
- Encode(argc, argv);
- }
- return 0;
- }
-
- Can someone see what's wrong with this ?
- am I not using strcmp() right ?
-
- Thanks a bunch (I don't have any more hair to pull from my head !)
-
- Otis
- Otis.Gospodnetic@mail.middlebury.edu
-
-